﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsImageResizer
{
    
    public partial class ImageForm : Form
    {
        private string fileName;
        private string fileNameTo;
        public ImageForm()
        {
            InitializeComponent();
        }

		public void CreateNewFile()
		{
			SetStatusBarInfo("Created new file.");
			this.fileName = null;
			this.Text = "Untitled";
		}

		public void LoadFile(string fileName)
		{
			
			this.fileName = Path.GetFileName(fileName);

            this.pictureBox.Load(fileName);
            pictureBox.Width = pictureBox.Image.Width;
            pictureBox.Height = pictureBox.Image.Height;
            //pictureBox.Size=pictureBox.Image.Size;

		}

		public void Save()
		{
			if (this.fileName == null)
			{
				if (saveFileDialog.ShowDialog() != DialogResult.OK)
				{
					return;
				}
				this.fileName = saveFileDialog.FileName;
                this.fileName = Path.GetFileName(this.fileName);
			}

            using (FileStream stream = new FileStream(Path.GetFullPath(this.fileName), FileMode.Open))
			{
                byte[] img = File.ReadAllBytes(this.fileName);
               stream.Write(img,0,img.Length);
			}

			SetStatusBarInfo("Saved file: " + this.fileName);
		}

		public void SetStatusBarInfo(string text)
		{
			MainForm mainForm = (MainForm)this.MdiParent;
			//mainForm.SetInfoStatusBar(text);
		}

		public void SetStatusBarLine(string text)
		{
			MainForm mainForm = (MainForm)this.MdiParent;
			//mainForm.SetLineStatusBar(text);
		}

		public void ShowLineNumber()
		{
			//int currentPos = textEditorRichTextBox.SelectionStart;
			//int line = pictureBox.GetLineFromCharIndex(currentPos);
			//SetStatusBarLine("Line: " + line);
		}

		private void EditorForm_Activated(object sender, System.EventArgs e)
		{
			ShowLineNumber();
		}

		private void EditorForm_FormClosed(object sender, System.EventArgs e)
		{
			if (this.fileName != null)
			{
				SetStatusBarInfo("Closed file: " + fileName);
			}
			else
			{
				SetStatusBarInfo("Closed file.");
			}
			SetStatusBarLine("");
		}

		private void textEditorRichTextBox_SelectionChanged(object sender, System.EventArgs e)
		{
			ShowLineNumber();
		}

        private void textEditorRichTextBox_TextChanged(object sender, System.EventArgs e)
        {

        }

        private void ImageForm_Load(object sender, EventArgs e)
        {

        }

        private void pictureBox_Click(object sender, EventArgs e)
        {

        }
    }
}
